<template>
  <div id="addPictureBatchPage" class="page-container">
    <div class="form-card">
      <h2 class="page-title">批量创建图片</h2>
      <a-form layout="vertical" :model="formData" @finish="handleSubmit">
        <a-form-item label="关键词" name="searchText">
          <a-input
            v-model:value="formData.searchText"
            placeholder="请输入关键词"
            class="custom-input"
          />
        </a-form-item>

        <a-form-item label="抓取数量" name="count">
          <a-input-number
            v-model:value="formData.count"
            placeholder="请输入数量"
            :min="1"
            :max="30"
            class="full-width-input"
          />
        </a-form-item>
<!--        后期使用redis实现数量自增-->
        <a-form-item label="抓取偏移量" name="startIndex">
          <a-input-number
            v-model:value="formData.startIndex"
            placeholder="请输入数量"
            class="full-width-input"
          />
        </a-form-item>

        <a-form-item label="名称前缀" name="namePrefix">
          <a-input
            v-model:value="formData.picPrefix"
            placeholder="请输入名称前缀（自动补充序号）"
            class="custom-input"
          />
          <div class="input-tip">例如输入"产品图"将生成：产品图1、产品图2...</div>
        </a-form-item>

        <a-form-item>
          <a-button
            type="primary"
            html-type="submit"
            size="large"
            class="submit-btn"
            :loading="loading"
          >
            <template #icon><rocket-two-tone /></template>
            立即执行
          </a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>


<script lang="ts" setup>
// 由于图片id是动态的，所以需要使用defineProps来定义props
import { reactive, ref } from 'vue'
import { uploadPictureByBatchUsingPost } from '@/apis/PictureInterface.ts'
import { message } from 'ant-design-vue'
import router from '@/router'

const formData = reactive<API.PictureUploadByBatchRequest>({
  count: 10,
})

const loading = ref(false)

const handleSubmit = async (values: any) => {
  loading.value = true;
  const res = await uploadPictureByBatchUsingPost({
    ...formData,
  })
  if (res.data.code === 0 && res.data.data) {
    message.success(`创建成功，共 ${res.data.data} 条`)
    router.push({
      path: '/',
    })
  } else {
    message.error('创建失败，' + res.data.message)
  }
  loading.value = false;
}


</script>

<style scoped>
.page-container {
  background: #f0f2f5;
  min-height: 100vh;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.form-card {
  background: white;
  padding: 32px 40px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 600px;
}

.page-title {
  color: #1f2d3d;
  text-align: center;
  margin-bottom: 32px;
  font-size: 24px;
  position: relative;
  padding-bottom: 16px;
}

.page-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: #1890ff;
}

.custom-input {
  border-radius: 6px;
}

.full-width-input {
  width: 100%;
}

.input-tip {
  font-size: 12px;
  color: #909399;
  margin-top: 8px;
}

.submit-btn {
  width: 100%;
  border-radius: 6px;
  height: 42px;
  font-weight: 500;
  transition: all 0.3s;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(24,144,255,0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .form-card {
    padding: 24px;
    margin: 16px;
  }

  .page-title {
    font-size: 20px;
    margin-bottom: 24px;
  }
}
</style>
